package com.blank.web.servlet;

import com.blank.web.bean.Student;
import com.blank.web.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "searchStudentServlet",urlPatterns = "/searchStuInfo")
public class searchStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       request.setCharacterEncoding("utf-8");
        String sName = request.getParameter("sName");
        System.out.println(sName);
        StudentService studentService = new StudentService();
        List<Student> studentList = studentService.Search(sName);
        //将studentList存入request中
        request.setAttribute("list",studentList);
        request.getRequestDispatcher("showStuInfo.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
